

import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
// import componentsRouter from './modules/components'
import operationRouter from './modules/operation'
import swiperRouter from './modules/swiper'
import noticeRouter from './modules/notice'
import linksRouter from './modules/links'
import maintainRouter from './modules/maintain'
import mobileRouter from './modules/mobile'
import userRouter from './modules/user'
import adviseRouter from './modules/report'
import buildRouter from  './modules/build'
import ServiceRouter from './modules/service'
import ApplyRouter from '@/router/modules/apply'
import houseRouter from '@/router/modules/house'
import Represent from '@/router/modules/represent'

export const constantRoutes = [
  Represent,
  // 设置
  operationRouter,
  //轮播图
  swiperRouter,
  //通知公告
  noticeRouter,
  //友情链接
  linksRouter,
  // 维护
  maintainRouter,
  //移动端管理
  mobileRouter,
  //用户管理
  userRouter,
  //投诉建议
  adviseRouter,
  //党建管理
  buildRouter,
  //家政服务管理
  ServiceRouter,
  //报修申请管理
  ApplyRouter,
  //房屋管理
  houseRouter,
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/auth-send',
    component: () => import('@/views/mobile/auth-send'),
    hidden: true
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '主页', icon: 'dashboard', affix: true }
      },
    ]
  },
  {
    path: '/enter',
    component: () => import('@/views/enter/index'),
    hidden: true
  },
  {
    path: '/setting/uploadPicture',
    component: () => import('@/components/uploadPicture/index.vue'),
    name: 'uploadPicture'
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [

]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  //mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
